package com.itheima.youdianda.controller;


import com.itheima.youdianda.common.R;
import com.itheima.youdianda.dto.AdvimgDto;
import com.itheima.youdianda.entity.YddAdvimg;
import com.itheima.youdianda.service.YddAdvimgService;
import com.itheima.youdianda.util.MyPages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-24
 */
@RestController
@RequestMapping("/ydd_advimg")
public class YddAdvimgController {
	@Autowired
	private YddAdvimgService yddAdvimgService;

	@GetMapping("/list")
	public R<MyPages<AdvimgDto>> list(String advimgdesc, String advimgpos, @RequestParam(defaultValue = "1") String page, @RequestParam(defaultValue = "10") String limit){
		MyPages<AdvimgDto> myPages = yddAdvimgService.listByPage(advimgdesc, advimgpos, page, limit);
		return R.success(myPages);
	}

	@GetMapping("/rowInfo")
	public R<YddAdvimg> rowInfo(int id){
		YddAdvimg yddAdvimg = yddAdvimgService.getById(id);
		return R.success(yddAdvimg);
	}

	@PostMapping("/update")
	public R<String> update(@RequestBody YddAdvimg yddAdvimg){
		yddAdvimgService.updateById(yddAdvimg);
		return R.success("修改成功!");
	}

	@PostMapping("/add")
	public R<String> add(@RequestBody YddAdvimg yddAdvimg){
		yddAdvimg.setDefault_data("1");
		yddAdvimgService.save(yddAdvimg);
		return R.success("添加成功!");
	}

	@GetMapping("/del")
	public R<String> del(int id){
		yddAdvimgService.removeById(id);
		return R.success("删除成功!");
	}

}
